rgdal: interface entre R and GDAL (Geospatial Data Abstraction Library) and PROJ4 librarie: raster / vector
sp: classes d’objets spatiaux pour R. (S4)
rgeos: interface entre R et GEOS (Geometry Engine - Open Source) library: area, perimeter, distances, dissolve, buffer, overlap, union, contains…
Toujours utilisé
sf Website: Simple Features for R Octobre 2016
sp, rgeos and rgdal tout dans le même package
Plus simple
Tidy data: compatible dplyr.
sf objects data structure:
Capable de lire n’importe quel format de données spatiale : shp, geojson, kml
## [1] "sf" "data.frame"
## Classes 'sf' and 'data.frame': 34 obs. of 24 variables:
## $ INSEE_COM: Factor w/ 34 levels "97201","97202",..: 1 2 3 4 5 6 7 8 9 10 ...
## $ STATUT : Factor w/ 3 levels "Commune simple",..: 1 1 1 1 1 1 1 1 2 1 ...
## $ LIBGEO : Factor w/ 34 levels "Basse-Pointe",..: 9 23 1 11 3 12 4 5 6 13 ...
## $ P13_POP : num 1830 3929 3565 3742 4464 ...
## $ C13_POP : num 1482 3190 2983 3157 3513 ...
## $ C13_CS1 : num 9.78 97.43 39.51 80.13 36.14 ...
## $ C13_CS2 : num 48.9 170.5 98.8 192.3 172.7 ...
## $ C13_CS3 : num 9.78 109.61 43.46 84.14 349.33 ...
## $ C13_CS4 : num 103 240 182 341 518 ...
## $ C13_CS5 : num 274 560 569 533 675 ...
## $ C13_CS6 : num 289 386 565 260 317 ...
## $ C13_CS7 : num 430 747 941 990 735 ...
## $ C13_CS8 : num 318 881 545 677 711 ...
## $ P08_POP : num 1691 3826 3804 3760 4515 ...
## $ C08_POP : num 1347 3068 3054 3039 3454 ...
## $ C08_CS1 : num 31.4 49 44.5 88.9 32.8 ...
## $ C08_CS2 : num 43.2 144 106.8 129.4 155.7 ...
## $ C08_CS3 : num 11.8 65.3 27.7 153.6 262.2 ...
## $ C08_CS4 : num 145 216 186 408 615 ...
## $ C08_CS5 : num 224 600 448 509 729 ...
## $ C08_CS6 : num 251 459 620 271 332 ...
## $ C08_CS7 : num 381 559 882 832 549 ...
## $ C08_CS8 : num 259 975 739 646 778 ...
## $ geometry :sfc_POLYGON of length 34; first list element: List of 1
## ..$ : num [1:55, 1:2] 699261 699226 699016 698406 698001 ...
## ..- attr(*, "class")= chr "XY" "POLYGON" "sfg"
## - attr(*, "sf_column")= chr "geometry"
## - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
## ..- attr(*, "names")= chr "INSEE_COM" "STATUT" "LIBGEO" "P13_POP" ...
## Simple feature collection with 34 features and 23 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: -61.2291 ymin: 14.39456 xmax: -60.8095 ymax: 14.8781
## epsg (SRID): 4326
## proj4string: +proj=longlat +datum=WGS84 +no_defs
## First 10 features:
## INSEE_COM STATUT LIBGEO P13_POP C13_POP
## 1 97201 Commune simple L'Ajoupa-Bouillon 1830 1481.801
## 2 97202 Commune simple Les Anses-d'Arlet 3929 3190.115
## 3 97203 Commune simple Basse-Pointe 3565 2983.215
## 4 97204 Commune simple Le Carbet 3742 3157.044
## 5 97205 Commune simple Case-Pilote 4464 3513.386
## 6 97206 Commune simple Le Diamant 6063 4766.876
## 7 97207 Commune simple Ducos 17051 14032.139
## 8 97208 Commune simple Fonds-Saint-Denis 813 684.000
## 9 97209 Préfecture de région Fort-de-France 84174 68712.330
## 10 97210 Commune simple Le François 18225 14959.798
## C13_CS1 C13_CS2 C13_CS3 C13_CS4 C13_CS5 C13_CS6 C13_CS7
## 1 9.780866 48.90433 9.780866 102.6991 273.8642 288.5355 430.3581
## 2 97.433459 170.50855 109.612642 239.5239 560.2424 385.6741 746.5743
## 3 39.510829 98.77707 43.461911 181.7498 568.9559 565.0048 940.5055
## 4 80.133275 192.31986 84.139939 340.5664 532.8800 260.4331 989.5457
## 5 36.137682 172.65782 349.330931 517.9734 674.5701 317.2085 734.7995
## 6 28.374581 251.31772 397.190830 802.5953 835.0234 506.6890 956.6287
## 7 85.296622 614.27717 772.462370 2016.3061 2716.9554 1548.7246 2936.4613
## 8 32.000000 16.00000 12.000000 68.0000 112.0000 100.0000 224.0000
## 9 86.572838 2720.48912 4000.386802 8407.4236 13799.2254 7309.1357 16184.2574
## 10 137.873479 817.80956 544.951619 1470.5494 2966.3701 2115.8299 3577.5536
## C13_CS8 P08_POP C08_POP C08_CS1 C08_CS2 C08_CS3 C08_CS4
## 1 317.8781 1691 1346.519 31.40569 43.18282 11.77713 145.2513
## 2 880.5453 3826 3067.742 49.00453 143.95079 65.33937 216.3534
## 3 545.2494 3804 3054.108 44.51803 106.84327 27.70011 186.0292
## 4 677.0259 3760 3038.656 88.93759 129.36377 153.61948 408.2622
## 5 710.7078 4515 3453.848 32.77765 155.69385 262.22121 614.5810
## 6 989.0568 5850 4569.721 33.41790 329.82460 338.35626 676.7125
## 7 3341.6553 16433 13441.442 106.52838 563.35180 629.34551 1785.4747
## 8 120.0000 873 708.000 16.00000 16.00000 16.00000 48.0000
## 9 16204.8388 89000 71566.825 119.06082 2480.10528 3976.89825 8630.6045
## 10 3328.8607 19189 15209.492 132.46653 666.44376 614.97272 1359.9284
## C08_CS5 C08_CS6 C08_CS7 C08_CS8 geometry
## 1 223.7655 251.2455 380.7940 259.0969 POLYGON ((-61.14848 14.8059...
## 2 600.3054 459.4174 558.8020 974.5694 POLYGON ((-61.0533 14.45579...
## 3 448.1481 620.2845 881.5853 738.9993 POLYGON ((-61.0846 14.85312...
## 4 509.2011 270.7288 832.0621 646.4813 POLYGON ((-61.16765 14.6753...
## 5 729.2055 331.8737 549.0257 778.4692 POLYGON ((-61.11754 14.6275...
## 6 760.2573 563.9271 743.5483 1123.6770 POLYGON ((-61.0533 14.45579...
## 7 2786.1717 1549.6171 2378.2314 3642.7213 POLYGON ((-60.954 14.55508,...
## 8 104.0000 124.0000 200.0000 184.0000 POLYGON ((-61.11316 14.7019...
## 9 15437.6017 7964.5133 15996.5794 16961.4616 POLYGON ((-61.0392 14.64185...
## 10 3079.8702 2219.3613 3277.7336 3858.7154 POLYGON ((-60.89389 14.6500...
Les projections/système de coordonées sont répertoriées grâce à un code le code epsg :
Préservations ? angles, aires, distance locales, …
## INSEE_COM STATUT LIBGEO P13_POP C13_POP
## 1 97201 Commune simple L'Ajoupa-Bouillon 1830 1481.8012
## 2 97202 Commune simple Les Anses-d'Arlet 3929 3190.1148
## 3 97203 Commune simple Basse-Pointe 3565 2983.2154
## 4 97204 Commune simple Le Carbet 3742 3157.0443
## 5 97205 Commune simple Case-Pilote 4464 3513.3858
## 6 97206 Commune simple Le Diamant 6063 4766.8763
## 7 97207 Commune simple Ducos 17051 14032.1389
## 8 97208 Commune simple Fonds-Saint-Denis 813 684.0000
## 9 97209 Préfecture de région Fort-de-France 84174 68712.3297
## 10 97210 Commune simple Le François 18225 14959.7983
## 11 97211 Commune simple Grand'Rivière 583 518.4111
## 12 97212 Commune simple Gros-Morne 10012 8291.2642
## 13 97213 Commune simple Le Lamentin 40040 32027.1180
## 14 97214 Commune simple Le Lorrain 7177 5980.0000
## 15 97215 Commune simple Macouba 1090 892.5087
## 16 97216 Commune simple Le Marigot 3481 2963.1131
## 17 97217 Sous-préfecture Le Marin 8543 6664.9936
## 18 97218 Commune simple Le Morne-Rouge 5021 4086.3533
## 19 97219 Commune simple Le Prêcheur 1632 1321.4080
## 20 97220 Commune simple Rivière-Pilote 12359 10226.8721
## 21 97221 Commune simple Rivière-Salée 12737 10018.1007
## 22 97222 Commune simple Le Robert 23296 18507.5496
## 23 97223 Commune simple Saint-Esprit 9524 7695.7080
## 24 97224 Commune simple Saint-Joseph 16885 13620.8735
## 25 97225 Sous-préfecture Saint-Pierre 4285 3469.1633
## 26 97226 Commune simple Sainte-Anne 4436 3650.1201
## 27 97227 Commune simple Sainte-Luce 9991 8099.6994
## 28 97228 Commune simple Sainte-Marie 17188 14241.0491
## 29 97229 Commune simple Schoelcher 19922 16614.2363
## 30 97230 Sous-préfecture La Trinité 13253 10572.2203
## 31 97231 Commune simple Les Trois-Îlets 7698 6160.4195
## 32 97232 Commune simple Le Vauclin 9097 7484.0000
## 33 97233 Commune simple Le Morne-Vert 1877 1576.6418
## 34 97234 Commune simple Bellefontaine 1568 1244.0000
## C13_CS1 C13_CS2 C13_CS3 C13_CS4 C13_CS5 C13_CS6
## 1 9.780866 48.904329 9.780866 102.69909 273.86424 288.53554
## 2 97.433459 170.508554 109.612642 239.52392 560.24239 385.67411
## 3 39.510829 98.777071 43.461911 181.74981 568.95593 565.00485
## 4 80.133275 192.319860 84.139939 340.56642 532.88002 260.43314
## 5 36.137682 172.657816 349.330931 517.97345 674.57007 317.20855
## 6 28.374581 251.317719 397.190830 802.59530 835.02339 506.68895
## 7 85.296622 614.277170 772.462370 2016.30614 2716.95542 1548.72465
## 8 32.000000 16.000000 12.000000 68.00000 112.00000 100.00000
## 9 86.572838 2720.489119 4000.386802 8407.42359 13799.22537 7309.13571
## 10 137.873479 817.809557 544.951619 1470.54935 2966.37006 2115.82989
## 11 8.498542 8.498542 0.000000 29.74490 84.98542 93.48397
## 12 87.680236 348.176203 117.594628 775.34763 1646.66063 1225.49544
## 13 105.134620 1394.623448 1987.809553 4467.33585 6767.07147 3829.16288
## 14 140.000000 212.000000 84.000000 356.00000 1056.00000 976.00000
## 15 3.797909 15.191638 3.797909 37.97909 136.72474 212.68293
## 16 21.052313 89.472331 42.104627 273.68007 478.94013 473.67705
## 17 47.947972 255.726938 211.783472 755.19824 1218.70857 835.10269
## 18 93.329084 201.394339 54.032628 371.73749 711.63199 628.74330
## 19 35.493065 31.549391 3.943674 90.70450 232.67676 212.95839
## 20 102.664033 441.779628 137.740661 831.63454 2128.10894 1385.38721
## 21 55.159184 437.708811 482.066415 1315.36217 2094.37108 1178.62565
## 22 109.836295 726.630357 755.613487 2182.43356 3754.08227 2687.21168
## 23 137.102386 253.881290 304.852245 889.15238 1391.32750 965.36544
## 24 65.074403 559.494607 678.745732 1788.00192 2601.94765 1823.61477
## 25 86.494739 152.637774 91.582664 339.87344 572.57468 361.24273
## 26 56.505102 208.555193 132.530147 336.97588 639.02133 485.83444
## 27 70.655988 578.369727 403.748500 1181.97373 1540.30053 864.02179
## 28 180.337051 490.843956 200.404618 1187.24653 2406.03624 2108.33487
## 29 44.419169 780.708185 1756.684719 2727.91907 2794.04105 1158.67612
## 30 89.839442 368.103065 623.619347 1349.43827 2112.97113 1168.16531
## 31 16.236905 393.626072 621.002172 888.73280 1120.16812 551.99533
## 32 168.000000 344.000000 196.000000 784.00000 1148.00000 652.00000
## 33 63.860507 79.825633 47.895380 175.61639 279.38972 171.62511
## 34 36.000000 48.000000 32.000000 184.00000 184.00000 232.00000
## C13_CS7 C13_CS8 P08_POP C08_POP C08_CS1 C08_CS2 C08_CS3
## 1 430.3581 317.8781 1691 1346.519 31.405688 43.18282 11.77713
## 2 746.5743 880.5453 3826 3067.742 49.004525 143.95079 65.33937
## 3 940.5055 545.2494 3804 3054.108 44.518027 106.84327 27.70011
## 4 989.5457 677.0259 3760 3038.656 88.937594 129.36377 153.61948
## 5 734.7995 710.7078 4515 3453.848 32.777652 155.69385 262.22121
## 6 956.6287 989.0568 5850 4569.721 33.417902 329.82460 338.35626
## 7 2936.4613 3341.6553 16433 13441.442 106.528379 563.35180 629.34551
## 8 224.0000 120.0000 873 708.000 16.000000 16.00000 16.00000
## 9 16184.2574 16204.8388 89000 71566.825 119.060817 2480.10528 3976.89825
## 10 3577.5536 3328.8607 19189 15209.492 132.466525 666.44376 614.97272
## 11 161.4723 131.7274 751 635.557 9.930579 19.86116 0.00000
## 12 2278.6241 1811.6853 10734 8644.872 127.304900 294.45494 182.32140
## 13 6571.0609 6904.9193 39410 30843.896 101.877950 1292.62883 1652.86865
## 14 1896.0000 1260.0000 7650 6228.000 196.000000 176.00000 68.00000
## 15 284.8432 197.4913 1284 1009.910 15.718439 23.57766 0.00000
## 16 931.5649 652.6217 3668 3009.328 12.216486 89.58757 36.64946
## 17 1618.3502 1722.1755 8954 6748.948 25.054350 225.48915 233.84060
## 18 1203.0656 822.4189 5150 4088.748 77.528696 142.81602 67.95410
## 19 311.7720 402.3102 1682 1277.592 101.847039 31.33755 11.75158
## 20 2363.5260 2836.0311 13617 10770.916 69.857243 436.85120 144.84662
## 21 2104.7438 2350.0636 12968 9980.573 67.247838 464.84423 407.52675
## 22 3839.5539 4452.1881 23903 18726.445 183.991915 691.81324 715.08916
## 23 1895.2591 1858.7676 9045 7170.159 93.014297 279.04289 232.53574
## 24 3309.7225 2794.2719 16966 13612.124 67.350778 534.14049 654.29614
## 25 1059.0207 805.7366 4496 3554.202 56.778156 186.55680 85.16723
## 26 962.6415 828.0566 4833 3806.386 53.437380 234.30236 90.43249
## 27 1823.8962 1636.7329 9424 7598.989 42.801686 513.62023 440.66281
## 28 3996.2112 3671.6347 19056 15246.407 169.852571 510.08977 142.60018
## 29 3735.6264 3616.1615 21737 17877.768 39.652508 854.68783 1668.64685
## 30 2676.1019 2183.9818 13802 10878.932 106.154507 428.26444 709.30370
## 31 1347.3065 1221.3516 7368 5778.766 20.815624 353.86560 562.02184
## 32 2152.0000 2040.0000 8947 7192.000 136.000000 196.00000 180.00000
## 33 423.0759 335.3532 1853 1548.475 63.690481 67.67114 55.72917
## 34 260.0000 268.0000 1454 1100.000 32.000000 44.00000 32.00000
## C08_CS4 C08_CS5 C08_CS6 C08_CS7 C08_CS8
## 1 145.25131 223.7655 251.2455 380.7940 259.0969
## 2 216.35336 600.3054 459.4174 558.8020 974.5694
## 3 186.02922 448.1481 620.2845 881.5853 738.9993
## 4 408.26222 509.2011 270.7288 832.0621 646.4813
## 5 614.58097 729.2055 331.8737 549.0257 778.4692
## 6 676.71252 760.2573 563.9271 743.5483 1123.6770
## 7 1785.47472 2786.1717 1549.6171 2378.2314 3642.7213
## 8 48.00000 104.0000 124.0000 200.0000 184.0000
## 9 8630.60453 15437.6017 7964.5133 15996.5794 16961.4616
## 10 1359.92836 3079.8702 2219.3613 3277.7336 3858.7154
## 11 24.82645 114.2017 114.2017 248.2645 104.2711
## 12 778.79732 1692.1665 1413.2480 2088.9298 2067.6493
## 13 4236.79443 6504.3040 4172.9710 5769.6155 7112.8355
## 14 336.00000 1084.0000 916.0000 1840.0000 1612.0000
## 15 43.22571 133.6067 263.2839 267.2135 263.2839
## 16 195.46378 549.7419 566.0305 789.9994 769.6386
## 17 692.11682 1319.1779 914.4838 1506.8716 1831.9141
## 18 354.99982 673.0346 662.3675 1138.0462 972.0006
## 19 90.09546 211.5285 152.7706 298.0418 380.2191
## 20 785.61458 2313.1329 1672.8122 2146.8257 3200.9753
## 21 1235.01644 2133.8041 1227.2317 1882.2404 2562.6611
## 22 1959.46192 3722.9151 2815.6525 3554.6276 5082.8933
## 23 716.98521 1306.0758 996.0281 1682.2772 1864.1999
## 24 1852.31160 2709.7794 1836.8577 2790.3848 3167.0027
## 25 237.89039 638.7264 498.8367 943.2416 907.0048
## 26 374.06166 871.4404 476.8259 887.8826 818.0030
## 27 1252.92208 1496.2424 808.1165 1354.0897 1690.5333
## 28 1170.05917 2597.9521 2443.1609 3857.8122 4354.8798
## 29 2924.74243 3124.7185 1241.8094 3696.2033 4327.3068
## 30 1483.30742 2111.6265 1126.3540 2406.8400 2507.0810
## 31 745.03620 1195.3682 525.5945 1082.6376 1293.4268
## 32 676.00000 1268.0000 1020.0000 1684.0000 2032.0000
## 33 159.22620 254.7619 167.1875 433.8914 346.3170
## 34 152.00000 212.0000 184.0000 248.0000 196.0000
## Simple feature collection with 34 features and 23 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: 690574.4 ymin: 1592426 xmax: 736126.5 ymax: 1645660
## epsg (SRID): 32620
## proj4string: +proj=utm +zone=20 +datum=WGS84 +units=m +no_defs
## First 10 features:
## INSEE_COM STATUT LIBGEO P13_POP C13_POP
## 1 97201 Commune simple L'Ajoupa-Bouillon 1830 1481.801
## 2 97202 Commune simple Les Anses-d'Arlet 3929 3190.115
## 3 97203 Commune simple Basse-Pointe 3565 2983.215
## 4 97204 Commune simple Le Carbet 3742 3157.044
## 5 97205 Commune simple Case-Pilote 4464 3513.386
## 6 97206 Commune simple Le Diamant 6063 4766.876
## 7 97207 Commune simple Ducos 17051 14032.139
## 8 97208 Commune simple Fonds-Saint-Denis 813 684.000
## 9 97209 Préfecture de région Fort-de-France 84174 68712.330
## 10 97210 Commune simple Le François 18225 14959.798
## C13_CS1 C13_CS2 C13_CS3 C13_CS4 C13_CS5 C13_CS6 C13_CS7
## 1 9.780866 48.90433 9.780866 102.6991 273.8642 288.5355 430.3581
## 2 97.433459 170.50855 109.612642 239.5239 560.2424 385.6741 746.5743
## 3 39.510829 98.77707 43.461911 181.7498 568.9559 565.0048 940.5055
## 4 80.133275 192.31986 84.139939 340.5664 532.8800 260.4331 989.5457
## 5 36.137682 172.65782 349.330931 517.9734 674.5701 317.2085 734.7995
## 6 28.374581 251.31772 397.190830 802.5953 835.0234 506.6890 956.6287
## 7 85.296622 614.27717 772.462370 2016.3061 2716.9554 1548.7246 2936.4613
## 8 32.000000 16.00000 12.000000 68.0000 112.0000 100.0000 224.0000
## 9 86.572838 2720.48912 4000.386802 8407.4236 13799.2254 7309.1357 16184.2574
## 10 137.873479 817.80956 544.951619 1470.5494 2966.3701 2115.8299 3577.5536
## C13_CS8 P08_POP C08_POP C08_CS1 C08_CS2 C08_CS3 C08_CS4
## 1 317.8781 1691 1346.519 31.40569 43.18282 11.77713 145.2513
## 2 880.5453 3826 3067.742 49.00453 143.95079 65.33937 216.3534
## 3 545.2494 3804 3054.108 44.51803 106.84327 27.70011 186.0292
## 4 677.0259 3760 3038.656 88.93759 129.36377 153.61948 408.2622
## 5 710.7078 4515 3453.848 32.77765 155.69385 262.22121 614.5810
## 6 989.0568 5850 4569.721 33.41790 329.82460 338.35626 676.7125
## 7 3341.6553 16433 13441.442 106.52838 563.35180 629.34551 1785.4747
## 8 120.0000 873 708.000 16.00000 16.00000 16.00000 48.0000
## 9 16204.8388 89000 71566.825 119.06082 2480.10528 3976.89825 8630.6045
## 10 3328.8607 19189 15209.492 132.46653 666.44376 614.97272 1359.9284
## C08_CS5 C08_CS6 C08_CS7 C08_CS8 geometry
## 1 223.7655 251.2455 380.7940 259.0969 POLYGON ((699261.2 1637681,...
## 2 600.3054 459.4174 558.8020 974.5694 POLYGON ((709840 1599026, 7...
## 3 448.1481 620.2845 881.5853 738.9993 POLYGON ((706092.8 1642964,...
## 4 509.2011 270.7288 832.0621 646.4813 POLYGON ((697314.8 1623213,...
## 5 729.2055 331.8737 549.0257 778.4692 POLYGON ((702756.8 1617978,...
## 6 760.2573 563.9271 743.5483 1123.6770 POLYGON ((709840 1599026, 7...
## 7 2786.1717 1549.6171 2378.2314 3642.7213 POLYGON ((720449.9 1610106,...
## 8 104.0000 124.0000 200.0000 184.0000 POLYGON ((703159.7 1626214,...
## 9 15437.6017 7964.5133 15996.5794 16961.4616 POLYGON ((711183.1 1619627,...
## 10 3079.8702 2219.3613 3277.7336 3858.7154 POLYGON ((726831.3 1620678,...
mtq_c <- st_centroid(mtq)
plot(st_geometry(mtq))
plot(st_geometry(mtq_c), add=TRUE, cex=1.2, col="red", pch=20)## Units: [m]
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0.000 35297.56 3091.501 12131.617 17136.310
## [2,] 35297.557 0.00 38332.602 25518.913 18605.249
## [3,] 3091.501 38332.60 0.000 15094.702 20226.198
## [4,] 12131.617 25518.91 15094.702 0.000 7177.011
## [5,] 17136.310 18605.25 20226.198 7177.011 0.000
mtq_u <- st_union(mtq)
plot(st_geometry(mtq), col="lightblue")
plot(st_geometry(mtq_u), add=T, lwd=2, border = "red")avec une variable de groupe :
library(dplyr)
mtq_u2 <- mtq %>%
group_by(STATUT) %>%
summarize(P13_POP=sum(P13_POP))
plot(st_geometry(mtq), col="lightblue")
plot(st_geometry(mtq_u2), add=T, lwd=2, border = "red", col=NA)mtq_b <- st_buffer(x = mtq_u, dist = 5000)
plot(st_geometry(mtq), col="lightblue")
plot(st_geometry(mtq_u), add=T, lwd=2)
plot(st_geometry(mtq_b), add=T, lwd=2, border = "red")m <- rbind(c(700015,1624212), c(700015,1641586), c(719127,1641586),
c(719127,1624212), c(700015,1624212))
p <- st_sf(st_sfc(st_polygon(list(m))), crs = st_crs(mtq))
plot(st_geometry(mtq))
plot(p, border="red", lwd=2, add=T)mtq_z <- st_intersection(x = mtq, y = p)
plot(st_geometry(mtq))
plot(st_geometry(mtq_z), col="red", border="green", add=T)google: “st_voronoi R sf” (https://github.com/r-spatial/sf/issues/474 & https://stackoverflow.com/questions/45719790/create-voronoi-polygon-with-simple-feature-in-r)
mtq_v <- st_voronoi(x = st_union(mtq_c))
mtq_v <- st_intersection(st_cast(mtq_v), st_union(mtq))
mtq_v <- st_join(x = st_sf(mtq_v), y = mtq_c, join=st_intersects)
mtq_v <- st_cast(mtq_v, "MULTIPOLYGON")
plot(st_geometry(mtq_v), col='lightblue')library(sf)
# Import geo layers
# Communes of Seine Maritime
sm <- st_read(dsn = "data/seine_maritime.geojson",
stringsAsFactors = F, quiet=TRUE)
# French departements
dep <- st_read(dsn = "data/dep.geojson",
stringsAsFactors = F, quiet=TRUE)
# change projection (lambert93)
sm <- st_transform(sm, 2154)
dep <- st_transform(dep, 2154)
# Import dataset
csp <- read.csv("data/data_seine_maritime.csv")
# merge geolayer and dataset
sm <- merge(sm, csp, by="INSEE_COM", all.x=TRUE)library(ggplot2)
ggplot()+geom_sf(data=dep,fill="ivory",color="ivory3")+
geom_sf_text(data=dep %>% filter(CODE_REG!=11),aes(label=CODE_DEPT),size=3,family="Palatino", fontface="bold")library(ggplot2)
bb = st_bbox(sm)
ggplot()+geom_sf(data=dep,fill="ivory",color="ivory3")+
geom_sf(data = sm %>% st_centroid,aes(size=act))+
coord_sf(xlim=bb[c(1,3)],ylim=bb[c(2,4)],ndiscr = 0)library(ggplot2)
bb = st_bbox(sm)
cols <- c("#e3b4a2", "#a2d5d6", "#debbd4",
"#afc2e3", "#b5dab6","#e9e2c1")
modlab <- c("Agriculteurs", "Artisans","Cadres",
"Employés","Prof. Inter.", "Ouvriers")
names(cols)=modlab
levels(sm$cat)=modlab
ggplot()+geom_sf(data=dep,fill="ivory",color="ivory3")+
geom_sf(data = sm,aes(fill=cat),size=0.1)+
scale_fill_manual("Dominant Socio-Professional\nCategory",values=cols)+
theme_minimal()+
coord_sf(xlim=bb[c(1,3)],ylim=bb[c(2,4)],ndiscr = 0)library(sf)
# Import geo layers
# Communes of Seine Maritime
sm <- st_read(dsn = "data/seine_maritime.geojson",
stringsAsFactors = F, quiet=TRUE)
# French departements
dep <- st_read(dsn = "data/dep.geojson",
stringsAsFactors = F, quiet=TRUE)
# change projection (lambert93)
sm <- st_transform(sm, 2154)
dep <- st_transform(dep, 2154)
# Import dataset
csp <- read.csv("data/data_seine_maritime.csv")
# merge geolayer and dataset
sm <- merge(sm, csp, by="INSEE_COM", all.x=TRUE)# Custom map of active population
par(mar=c(0.2,0.2,1.4,0.2))
bb <- st_bbox(sm)
# the bbox is used to center the map on the Seine Maritime depatement
plot(st_geometry(dep), col = "ivory", border="ivory3", bg="azure",
xlim = bb[c(1,3)], ylim = bb[c(2,4)])
plot(st_geometry(sm), col="cornsilk2", border = NA, lwd = 0.5, add=T)
propSymbolsLayer(sm, var = "act", col="darkblue", inches = 0.6,
border = "white", lwd=0.7, symbols = "square",
legend.style = "e", legend.pos="topleft",
legend.title.txt = "Labor Force\n(2014)",
legend.values.rnd = 0)
# Scale Bar
barscale(size = 10)
# North Arrow
north(pos = "topright", col = "darkblue")
# Full layout
layoutLayer(title = "Workforce in Seine-Maritime",
sources = "Insee, 2018", author = "Kim & Tim, 2018",
col = "darkblue", coltitle = "white", tabtitle = TRUE,
frame = TRUE, scale = NULL, north = FALSE)
title("Active Population")#To display qualitative data modalities
mod <- c("agr", "art", "cad", "int", "emp", "ouv")
# labels in the legedn
modlab <- c("Agriculteurs", "Artisans","Cadres",
"Prof. Inter.", "Employés", "Ouvriers")
# colors
cols <- c("#e3b4a2", "#a2d5d6", "#debbd4",
"#b5dab6", "#afc2e3", "#e9e2c1")
par(mar=c(0.2,0.2,1.4,0.2))
plot(st_geometry(dep), col = "ivory", border="ivory3", bg="azure",
xlim = bb[c(1,3)], ylim = bb[c(2,4)])
typoLayer(sm, var = "cat",
border = "ivory", lwd = 0.5,
legend.values.order = mod,
col = cols,
add=TRUE, legend.pos = "n")
# functions are dedicated to legend display
legendTypo(title.txt = "Dominant Socio-Professional\nCategory",
col = cols,
categ = modlab,
nodata = F)
barscale(size = 10)
north(pos = "topright", col = "darkblue")
layoutLayer(title = "Workforce Distribution in Seine-Maritime",
sources = "Insee, 2018", author = "Kim & Tim, 2018",
col = "darkblue", coltitle = "white", tabtitle = TRUE,
frame = TRUE, scale = NULL, north = FALSE)# Compute the share of "managers" in the active population
sm$pcad <- 100 * sm$cad / sm$act
# The getBreaks() function is used to classify the variable
bks <- getBreaks(v = sm$pcad, method = "quantile", nclass = 6)
# The carto.pal() function give access to various palettes
cols <- carto.pal("green.pal", 3,"wine.pal",3)
# Create the map
par(mar=c(0.2,0.2,1.4,0.2))
plot(st_geometry(dep), col = "ivory", border="ivory3", bg="azure",
xlim = bb[c(1,3)], ylim = bb[c(2,4)])
choroLayer(sm, var = "pcad", breaks = bks,
col = cols, border = "grey80",
legend.values.rnd = 1,
lwd = 0.4, legend.pos = "topleft",
legend.title.txt = "Share of managers (%)", add=T)
# Add a layout
layoutLayer(title = "Managers",
sources = "Insee, 2018", author = "Kim & Tim, 2018",
theme = "green.pal",
col = "darkred", coltitle = "white",
tabtitle = TRUE,
frame = TRUE, scale = 10)
north(pos = "topright")library(leaflet)
sm.center.4326 = sm %>% st_centroid()%>% st_transform(4326)
leaflet(data = sm.center.4326 ) %>%
addTiles() %>%
addCircleMarkers(radius =~ sqrt(act/100)*1.5,
fillColor = "#449944",
stroke=FALSE,
fillOpacity = 1,
popup = ~paste(LIBELLE,":",act,"actifs"))https://rstudio.github.io/leaflet/
Charger les contours des départements français contenus dans le répertoire exo6_dep
Calculer à partir des données communales contenues dans le fichier exo6_data.csv des taux de naissances par départements.
Joindre les deux tables et vérifier ques des données sont associées à chaque départements.
Corriger les problèmes de jointure éventuels.
Exporter les données en geojson
Réaliser une carte choroplèthe avec ces données.
Calculer et afficher les voronois associés aux stations velib de new-york.
Les données sont disponnibles dans le fichiers json ./data/input_NewYork.json
Créer une data.frame avec les latitudes, longitudes et nbr de vélos des stations
Utiliser la fonction st_as_sf avec l’option coords pour transformer celle-ci en data.frame spatiale.
Faire une carte interactive des monuments historiques à paris
Faire une carte en symbol proportionel avec le nombre de monuments par iris.
regarder les fonctions st_contains,st_within
! vous travaillerez avec des données en lambert 93
Calculer la densité de monuments par hectare pour chaque iris.
Faire une carte choroplète
Les contours des iris sont disponnibles dans le répertoire “data/CONTOURS-IRIS/”
Les données sont disponibles dans le répertoire “data/monuments_paris.geojson”
Faire une carte en symboles proportionels du nombre de vélos dans les stations vélib à NewYork.
Utiliser un fond de carte open street map avec la library cartography.
(dépot staRday)[http://github.comeetie.fr/satRday]